<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>demo</title>
  <script type="text/javascript" src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <p>{{count}}</p>
    <button @click="add">+</button>
    <button @click="add2(2)">+</button>
    <button @click="sub(2,$event)">-</button>
  </div>
</body>
<script type="text/javascript">
  Vue.config.productionTip = false
  const vm = new Vue({
    el: "#app",
    data() {
      return {
        count: 1
      }
    },
    methods: {
      // 此时就是事件对象  不传实参,则事件对象的第一个形参即使事件对象

      add(a) {
        console.log(a);
        this.count++
      },
      // 此时传参,就会覆盖事件对象 接受实参
      add2(a) {
        console.log(a);
        this.count += a
      },
      // 如果需要传参且同时需要事件对象 则用$event传参
      sub(e,a) {
        console.log(a);
        this.count -= e
      }
    }
  })
</script>

</html>